package com.ruoyi.common.core.utils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

/*IPMS系统通用工具类*/
public class IPMSUtils {

    public static void main(String[] args) {
        //合同编号
        System.out.println(spawnNo("CON.", 5));
        //专利编号
        System.out.println(spawnNo("PATENT.", 5));
        //案件（业务）编号
        System.out.println(spawnNo("CASE.", 5));
        //客户编号
        System.out.println(spawnNo("CUS.", 5));
    }

    //随机编号
    public static String spawnNo(String prefix, int len) {

        if (len <= 0) {
            throw new RuntimeException("参数异常,请输入大于0数字");
        }
        // 初始编号
        String no = prefix + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
        int total = 1;
        for (int j = 0; j < len; j++)
            total *= 10;
        // 随机编号字符串
        String num = new Random().nextInt(total) + "";
        // 空位补0
        int i = 0;
        for (; ; ) {
            if (i >= len - num.length())
                break;
            no += "0";
            i++;
        }
        return no += num;
    }
}
